Predicting when does the algae blossoms algaeDataset is our Dataset name
library(DMwR)
## Loading required package: lattice
## Loading required package: grid
algaeDataset <- algae
From the below summary we can observe that during the winter season maximum water samples has been taken, also from the chemical parameters summary we undertand that we have some NA’s value
summary(algaeDataset)
## season size speed mxPH mnO2
## autumn:40 large :45 high :84 Min. :5.600 Min. : 1.500
## spring:53 medium:84 low :33 1st Qu.:7.700 1st Qu.: 7.725
## summer:45 small :71 medium:83 Median :8.060 Median : 9.800
## winter:62 Mean :8.012 Mean : 9.118
## 3rd Qu.:8.400 3rd Qu.:10.800
## Max. :9.700 Max. :13.400
## NA's :1 NA's :2
## Cl NO3 NH4 oPO4
## Min. : 0.222 Min. : 0.050 Min. : 5.00 Min. : 1.00
## 1st Qu.: 10.981 1st Qu.: 1.296 1st Qu.: 38.33 1st Qu.: 15.70
## Median : 32.730 Median : 2.675 Median : 103.17 Median : 40.15
## Mean : 43.636 Mean : 3.282 Mean : 501.30 Mean : 73.59
## 3rd Qu.: 57.824 3rd Qu.: 4.446 3rd Qu.: 226.95 3rd Qu.: 99.33
## Max. :391.500 Max. :45.650 Max. :24064.00 Max. :564.60
## NA's :10 NA's :2 NA's :2 NA's :2
## PO4 Chla a1 a2
## Min. : 1.00 Min. : 0.200 Min. : 0.00 Min. : 0.000
## 1st Qu.: 41.38 1st Qu.: 2.000 1st Qu.: 1.50 1st Qu.: 0.000
## Median :103.29 Median : 5.475 Median : 6.95 Median : 3.000
## Mean :137.88 Mean : 13.971 Mean :16.92 Mean : 7.458
## 3rd Qu.:213.75 3rd Qu.: 18.308 3rd Qu.:24.80 3rd Qu.:11.375
## Max. :771.60 Max. :110.456 Max. :89.80 Max. :72.600
## NA's :2 NA's :12
## a3 a4 a5 a6
## Min. : 0.000 Min. : 0.000 Min. : 0.000 Min. : 0.000
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000
## Median : 1.550 Median : 0.000 Median : 1.900 Median : 0.000
## Mean : 4.309 Mean : 1.992 Mean : 5.064 Mean : 5.964
## 3rd Qu.: 4.925 3rd Qu.: 2.400 3rd Qu.: 7.500 3rd Qu.: 6.925
## Max. :42.800 Max. :44.600 Max. :44.400 Max. :77.600
##
## a7
## Min. : 0.000
## 1st Qu.: 0.000
## Median : 1.000
## Mean : 2.495
## 3rd Qu.: 2.400
## Max. :31.600
##
Removing the NA from the dataset
algaeDataset <- na.omit(algaeDataset)
summary(algaeDataset)
## season size speed mxPH mnO2
## autumn:36 large :42 high :76 Min. :7.000 Min. : 1.500
## spring:48 medium:83 low :31 1st Qu.:7.777 1st Qu.: 7.675
## summer:43 small :59 medium:77 Median :8.100 Median : 9.750
## winter:57 Mean :8.078 Mean : 9.019
## 3rd Qu.:8.400 3rd Qu.:10.700
## Max. :9.500 Max. :13.400
## Cl NO3 NH4 oPO4
## Min. : 0.80 Min. : 0.050 Min. : 5.80 Min. : 1.25
## 1st Qu.: 11.85 1st Qu.: 1.364 1st Qu.: 49.38 1st Qu.: 18.56
## Median : 35.08 Median : 2.820 Median : 115.71 Median : 46.28
## Mean : 44.88 Mean : 3.384 Mean : 537.67 Mean : 78.27
## 3rd Qu.: 58.52 3rd Qu.: 4.540 3rd Qu.: 235.25 3rd Qu.:102.83
## Max. :391.50 Max. :45.650 Max. :24064.00 Max. :564.60
## PO4 Chla a1 a2
## Min. : 2.50 Min. : 0.200 Min. : 0.00 Min. : 0.000
## 1st Qu.: 50.34 1st Qu.: 2.075 1st Qu.: 1.40 1st Qu.: 0.000
## Median :115.60 Median : 5.522 Median : 4.85 Median : 3.600
## Mean :146.58 Mean : 13.883 Mean :15.32 Mean : 7.777
## 3rd Qu.:220.25 3rd Qu.: 18.308 3rd Qu.:19.32 3rd Qu.:11.700
## Max. :771.60 Max. :110.456 Max. :89.80 Max. :72.600
## a3 a4 a5 a6
## Min. : 0.000 Min. : 0.000 Min. : 0.000 Min. : 0.000
## 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000
## Median : 1.700 Median : 0.000 Median : 2.650 Median : 0.000
## Mean : 4.613 Mean : 1.846 Mean : 5.493 Mean : 6.447
## 3rd Qu.: 5.525 3rd Qu.: 2.425 3rd Qu.: 8.000 3rd Qu.: 7.975
## Max. :42.800 Max. :44.600 Max. :44.400 Max. :77.600
## a7
## Min. : 0.000
## 1st Qu.: 0.000
## Median : 1.000
## Mean : 2.665
## 3rd Qu.: 2.700
## Max. :31.600
From this histogram we come to know that during winter season maximum PH is been recorded
library(ggplot2)
ggplot(algaeDataset,aes(mxPH,fill = season)) + geom_histogram(colour = "black")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
As we can see from the boxplot, we have a lot of outliers thus concluding that these values must have a lot of effect on the orthophoshate chemical count of the river
boxplot(algaeDataset$oPO4, ylab="Orthophosphate Count")
As we can see from the below graph that maximum times when the size of the river is medium we have taken the samples to identify the algae blossoms
ggplot(algaeDataset,aes(x=size)) + geom_bar(colour = "Red")
Here we are doing a bivariate boxplot which is helping us to understand about algae 1 that in what kind of the size of the river does it blossom more, so here we say that when the river size is small algae 1 blossoms a lot and we also see lot of outliers river size is medium
Similarily by looking at the other bivariate boxplots graphs we can summarize the below for all the other 6 different types algaes with respect to river size,season,speed components: Algae2 = medium,summer,low Algae3 = medium,spring, medium Algae4 = medium,spring, medium Algae5 = medium, summer, medium Algae6 = medium, autumn, medium Alage7 = medium, autumn, medium
library(lattice)
library(Hmisc)
## Warning: package 'Hmisc' was built under R version 3.5.2
## Loading required package: survival
## Loading required package: Formula
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, units
bwplot(size~a1,data=algaeDataset,xlab = "Algae A1",ylab = "River size")
bwplot(season~a1,data=algaeDataset,xlab = "Algae A1",ylab = "Season")
bwplot(speed~a1,data=algaeDataset,xlab = "Algae A1",ylab = "River speed")
bwplot(size ~ a1,data=algae,panel=panel.bpplot,probs=seq(.01,.49,by=.01),datadensity=TRUE,ylab='River Size',xlab='Algal A1')
bwplot(size~a2,data=algaeDataset,xlab = "Algae A2",ylab = "River size")
bwplot(season~a2,data=algaeDataset,xlab = "Algae A2",ylab = "Season")
bwplot(speed~a2,data=algaeDataset,xlab = "Algae A2",ylab = "River speed")
bwplot(size~a3,data=algaeDataset,xlab = "Algae A3",ylab = "River size")
bwplot(season~a3,data=algaeDataset,xlab = "Algae A3",ylab = "Season")
bwplot(speed~a3,data=algaeDataset,xlab = "Algae A3",ylab = "River speed")
bwplot(size~a4,data=algaeDataset,xlab = "Algae A4",ylab = "River size")
bwplot(season~a4,data=algaeDataset,xlab = "Algae A4",ylab = "Season")
bwplot(speed~a4,data=algaeDataset,xlab = "Algae A4",ylab = "River speed")
bwplot(size~a5,data=algaeDataset,xlab = "Algae A5",ylab = "River size")
bwplot(season~a5,data=algaeDataset,xlab = "Algae A5",ylab = "Season")
bwplot(speed~a5,data=algaeDataset,xlab = "Algae A5",ylab = "River speed")
bwplot(size~a6,data=algaeDataset,xlab = "Algae A6",ylab = "River size")
bwplot(season~a6,data=algaeDataset,xlab = "Algae A6",ylab = "Season")
bwplot(speed~a6,data=algaeDataset,xlab = "Algae A6",ylab = "River speed")
bwplot(size~a7,data=algaeDataset,xlab = "Algae A7",ylab = "River size")
bwplot(season~a7,data=algaeDataset,xlab = "Algae A7",ylab = "Season")
bwplot(speed~a7,data=algaeDataset,xlab = "Algae A7",ylab = "River speed")
plot(algaeDataset$a1 ~ algaeDataset$Cl)
Here we have calculated covriance and column Means for the normal distribution check
colnames(algaeDataset)
## [1] "season" "size" "speed" "mxPH" "mnO2" "Cl" "NO3"
## [8] "NH4" "oPO4" "PO4" "Chla" "a1" "a2" "a3"
## [15] "a4" "a5" "a6" "a7"
x <- dist(scale(algaeDataset[, c("mxPH", "mnO2", "Cl","NO3","NH4","oPO4","PO4","Chla")],
center = FALSE))
as.dist(round(as.matrix(x), 2)[1:12, 1:12])
## 1 2 3 4 5 6 7 8 9 10 11
## 2 3.99
## 3 1.47 3.32
## 4 2.25 3.75 1.36
## 5 1.89 4.26 1.29 1.73
## 6 1.45 4.68 1.51 2.04 0.98
## 7 2.18 3.81 1.23 0.63 1.78 1.90
## 8 1.91 4.09 0.99 0.95 1.09 1.27 0.76
## 9 2.41 4.15 1.62 1.01 2.04 2.25 1.13 1.25
## 10 2.54 4.30 1.55 1.33 1.98 2.13 1.10 1.11 0.78
## 11 2.59 4.47 1.67 1.42 2.00 2.11 1.18 1.14 0.86 0.19
## 12 2.61 4.50 1.67 1.49 2.01 2.09 1.19 1.14 1.01 0.28 0.17
x <- algaeDataset[, c("mxPH", "mnO2", "Cl","NO3","NH4","oPO4","PO4","Chla")]
cm <- colMeans(x)
S <- cov(x)
d <- apply(x, MARGIN = 1, function(x)t(x - cm) %*% solve(S) %*% (x - cm))
d
## 1 2 3 4 5 6
## 6.308049 19.106097 2.421095 5.180995 10.294317 7.399293
## 7 8 9 10 11 12
## 2.041773 1.378710 12.205272 1.197181 1.921584 3.798214
## 13 14 15 16 17 18
## 8.532871 2.830503 1.439196 5.165389 2.622491 1.825596
## 19 20 21 22 23 24
## 3.608542 58.031899 25.777324 6.083269 1.293435 2.409365
## 25 26 27 29 30 31
## 1.691277 1.445833 7.016084 1.342879 6.862262 5.058512
## 32 33 34 35 36 37
## 7.307562 1.909092 8.632794 31.685679 4.697365 2.824579
## 39 40 41 42 43 44
## 3.936960 3.833429 7.125914 1.908280 13.210620 13.131659
## 45 46 47 49 50 51
## 5.733295 5.061218 2.986639 2.483175 5.431851 1.859074
## 52 53 54 64 65 66
## 2.127574 1.951258 2.090195 2.905784 6.098314 3.784768
## 67 68 69 70 71 72
## 6.337565 8.800744 13.830102 13.513559 4.687019 4.334381
## 73 74 75 76 77 78
## 8.476801 4.075346 4.546652 10.461680 1.733699 3.403869
## 79 80 81 82 83 84
## 8.807962 2.613294 2.985317 4.259104 4.981331 4.304431
## 85 86 87 88 89 90
## 3.437738 3.278232 4.128853 25.149504 39.506861 5.501486
## 91 92 93 94 95 96
## 13.788324 4.286977 4.112380 2.979496 4.062759 5.674828
## 97 98 99 100 101 102
## 11.629657 22.127963 6.699621 7.079427 5.779818 6.160962
## 103 104 105 106 107 108
## 5.127619 10.636963 23.437896 12.990154 19.350300 2.124670
## 109 110 111 112 113 114
## 2.776525 1.604639 4.785924 2.079407 3.877778 3.800045
## 115 117 118 119 120 121
## 2.172866 4.962100 2.967282 6.686641 6.390291 6.210870
## 122 123 124 125 126 127
## 3.344137 5.729451 3.735153 1.605119 3.616362 23.986556
## 128 129 130 131 132 133
## 24.607705 4.143984 2.100551 2.340132 4.518660 22.476839
## 134 135 136 137 138 139
## 63.942596 8.603364 4.850736 2.216286 2.455642 2.940920
## 140 141 142 143 144 145
## 6.700856 4.176732 1.403138 1.257009 11.020921 12.375073
## 146 147 148 149 150 151
## 14.543299 1.467437 1.348421 1.598294 4.391603 4.050456
## 152 153 154 155 156 157
## 7.058305 161.168546 8.288272 5.881847 8.468986 15.397865
## 158 159 160 162 163 164
## 7.938589 1.610956 3.237650 21.289695 21.783274 20.149452
## 165 166 167 168 169 170
## 3.879358 4.280981 9.466264 2.935196 6.357279 5.180706
## 171 172 173 174 175 176
## 7.223011 16.399980 2.507884 2.278454 16.633284 14.495956
## 177 178 179 180 181 182
## 4.928755 2.053170 2.780939 4.186970 2.277912 3.296089
## 183 185 186 187 188 189
## 2.185410 1.490406 6.266247 3.768446 1.625527 2.158205
## 190 191 192 193 194 195
## 2.233151 4.644156 1.825111 3.490051 2.398118 3.397172
## 196 197 198 200
## 3.264242 1.595691 7.517249 2.631665
S
## mxPH mnO2 Cl NO3 NH4
## mxPH 0.2225065 -0.1166057 3.26578 -0.3146066 -147.8650
## mnO2 -0.1166057 5.7944078 -29.82509 1.0997298 -382.7583
## Cl 3.2657796 -29.8250876 2215.30207 38.4726809 6309.3683
## NO3 -0.3146066 1.0997298 38.47268 15.0133862 5704.5208
## NH4 -147.8649973 -382.7582810 6309.36826 5704.5208456 4127337.0433
## oPO4 3.9421181 -87.7889395 1653.33413 47.7364490 41267.4404
## PO4 6.1710802 -144.1914158 2705.30776 78.5551787 52300.3410
## Chla 4.1277801 -6.4007720 136.35243 11.4240425 3754.8089
## oPO4 PO4 Chla
## mxPH 3.942118 6.17108 4.127780
## mnO2 -87.788939 -144.19142 -6.400772
## Cl 1653.334129 2705.30776 136.352430
## NO3 47.736449 78.55518 11.424043
## NH4 41267.440358 52300.34101 3754.808912
## oPO4 8578.739540 10905.44454 200.672650
## PO4 10905.444542 16668.91384 650.137379
## Chla 200.672650 650.13738 410.655232
cm ##from the column means we can say that mxPH,mnO2,NO3 and Chla are related because the column means are close enough
## mxPH mnO2 Cl NO3 NH4 oPO4
## 8.078288 9.018587 44.880886 3.384071 537.671598 78.269446
## PO4 Chla
## 146.577647 13.882799
For PH level we are having a symmetric distribution with flat tails MNo2 - negatively skewed Cl - positively skewed No3 - positively skewed NH4 - symmetric with flat tails on the right OPo4 - positive skewed Po4 - symmetric with flat tails CHla - negatively skewed with lot of outliers
{qqnorm(algaeDataset[,"mxPH"], main = "PH level")
qqline(algaeDataset[,"mxPH"])}
{qqnorm(algaeDataset[,"mnO2"], main = "MnO2 level")
qqline(algaeDataset[,"mnO2"])}
{qqnorm(algaeDataset[,"Cl"], main = "Cl level")
qqline(algaeDataset[,"Cl"])}
{qqnorm(algaeDataset[,"NO3"], main = "NO3 level")
qqline(algaeDataset[,"NO3"])}
{qqnorm(algaeDataset[,"NH4"], main = "NH4 level")
qqline(algaeDataset[,"NH4"])}
{qqnorm(algaeDataset[,"oPO4"], main = "oPO4 level")
qqline(algaeDataset[,"oPO4"])}
{qqnorm(algaeDataset[,"PO4"], main = "PO4 level")
qqline(algaeDataset[,"PO4"])}
{qqnorm(algaeDataset[,"Chla"], main = "Chla level")
qqline(algaeDataset[,"Chla"])}
{plot(qchisq((1:nrow(x) - 1/2) / nrow(x), df = 8), sort(d),
xlab = expression(paste(chi[3]^2, " Quantile")),
ylab = "Ordered distances")
abline(a = 0, b = 1)} ##symmetric distribution with flat tail on the right
Now we will perform t-test statistics for the season and the frequencies of the algae
with(data=algaeDataset,t.test(a1[season=="winter"],a1[season=="spring"],var.equal=TRUE)) ## with this we say that yes there is a lot of algaes 1 blossmings during winter and spring
##
## Two Sample t-test
##
## data: a1[season == "winter"] and a1[season == "spring"]
## t = 0.97289, df = 103, p-value = 0.3329
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -4.139611 12.111760
## sample estimates:
## mean of x mean of y
## 16.66316 12.67708
with(data=algaeDataset,t.test(a1[season=="summer"],a1[season=="autumn"],var.equal=TRUE)) ## with this we say that yes there is a lot of algaes 1 blossmings during summer and autumn too
##
## Two Sample t-test
##
## data: a1[season == "summer"] and a1[season == "autumn"]
## t = -0.30938, df = 77, p-value = 0.7579
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -10.255095 7.496956
## sample estimates:
## mean of x mean of y
## 15.32093 16.70000
with(data=algaeDataset,t.test(a2[season=="winter"],a2[season=="spring"],var.equal=TRUE)) ##alage 2 also we can see the same amount of blossoms
##
## Two Sample t-test
##
## data: a2[season == "winter"] and a2[season == "spring"]
## t = 0.1761, df = 103, p-value = 0.8606
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -3.645874 4.356401
## sample estimates:
## mean of x mean of y
## 7.538596 7.183333
with(data=algaeDataset,t.test(a3[season=="winter"],a3[season=="spring"],var.equal=TRUE)) ## alage 3 also we can see the same amount of blossoms
##
## Two Sample t-test
##
## data: a3[season == "winter"] and a3[season == "spring"]
## t = -1.5426, df = 103, p-value = 0.126
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -5.8004043 0.7249657
## sample estimates:
## mean of x mean of y
## 5.078947 7.616667
with(data=algaeDataset,t.test(a4[season=="winter"],a4[season=="spring"],var.equal=TRUE)) ## alage 4 also we can see the same amount of blossoms
##
## Two Sample t-test
##
## data: a4[season == "winter"] and a4[season == "spring"]
## t = -0.88398, df = 103, p-value = 0.3788
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -2.740677 1.050764
## sample estimates:
## mean of x mean of y
## 1.917544 2.762500
with(data=algaeDataset,t.test(a5[season=="winter"],a5[season=="spring"],var.equal=TRUE)) ## alage 5 also we can see the same amount of blossoms
##
## Two Sample t-test
##
## data: a5[season == "winter"] and a5[season == "spring"]
## t = 0.82943, df = 103, p-value = 0.4088
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.371902 3.344270
## sample estimates:
## mean of x mean of y
## 4.640351 3.654167
with(data=algaeDataset,t.test(a6[season=="winter"],a6[season=="spring"],var.equal=TRUE)) ## alage 6 also we can see the same amount of blossoms
##
## Two Sample t-test
##
## data: a6[season == "winter"] and a6[season == "spring"]
## t = 1.7685, df = 103, p-value = 0.07994
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.3745924 6.5443292
## sample estimates:
## mean of x mean of y
## 5.447368 2.362500
with(data=algaeDataset,t.test(a7[season=="winter"],a7[season=="spring"],var.equal=TRUE)) ## alage 7 also we can see the same amount of blossoms
##
## Two Sample t-test
##
## data: a7[season == "winter"] and a7[season == "spring"]
## t = -0.29231, df = 103, p-value = 0.7706
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -2.402050 1.784945
## sample estimates:
## mean of x mean of y
## 2.578947 2.887500
For all the algaes all the hotelling test were significant except for algae 6 where we are getting the NA value
library(Hotelling)
## Loading required package: corpcor
t2testalgae <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a1, data=algaeDataset)
cat("T2 statistic =",t2testalgae$stat[[1]],"\n")
## T2 statistic = 5.56422
print(t2testalgae)
## Test stat: 0.56029
## Numerator df: 8
## Denominator df: 29
## P-value: 0.8011
t2testalgae2 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a2, data=algaeDataset)
cat("T2 statistic =",t2testalgae2$stat[[1]],"\n")
## T2 statistic = 7.376566
print(t2testalgae2)
## Test stat: 0.82277
## Numerator df: 8
## Denominator df: 58
## P-value: 0.5859
t2testalgae3 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a3, data=algaeDataset)
cat("T2 statistic =",t2testalgae3$stat[[1]],"\n")
## T2 statistic = 3.961561
print(t2testalgae3)
## Test stat: 0.44568
## Numerator df: 8
## Denominator df: 63
## P-value: 0.8888
t2testalgae4 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a4, data=algaeDataset)
cat("T2 statistic =",t2testalgae4$stat[[1]],"\n")
## T2 statistic = 12.07326
print(t2testalgae4)
## Test stat: 1.4066
## Numerator df: 8
## Denominator df: 96
## P-value: 0.2036
t2testalgae5 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a5, data=algaeDataset)
cat("T2 statistic =",t2testalgae5$stat[[1]],"\n")
## T2 statistic = 18.55548
print(t2testalgae5)
## Test stat: 2.0697
## Numerator df: 8
## Denominator df: 58
## P-value: 0.0537
t2testalgae6 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a6, data=algaeDataset)
cat("T2 statistic =",t2testalgae6$stat[[1]],"\n")
## T2 statistic = NA
print(t2testalgae6)
## Test stat: NA
## Numerator df: 8
## Denominator df: 86
## P-value: NA
t2testalgae7 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a7, data=algaeDataset)
cat("T2 statistic =",t2testalgae7$stat[[1]],"\n")
## T2 statistic = 15.27807
print(t2testalgae7)
## Test stat: 1.7629
## Numerator df: 8
## Denominator df: 84
## P-value: 0.09601
dim(algaeDataset)
## [1] 184 18
numericAlgaeData <- algaeDataset[,-c(1,2,3,12,13,14,15,16,17,18)]
cor(numericAlgaeData)
## mxPH mnO2 Cl NO3 NH4
## mxPH 1.00000000 -0.10269374 0.14709539 -0.1721302 -0.15429757
## mnO2 -0.10269374 1.00000000 -0.26324536 0.1179077 -0.07826816
## Cl 0.14709539 -0.26324536 1.00000000 0.2109583 0.06598336
## NO3 -0.17213024 0.11790769 0.21095831 1.0000000 0.72467766
## NH4 -0.15429757 -0.07826816 0.06598336 0.7246777 1.00000000
## oPO4 0.09022909 -0.39375269 0.37925596 0.1330145 0.21931121
## PO4 0.10132957 -0.46396073 0.44519118 0.1570297 0.19939575
## Chla 0.43182377 -0.13121671 0.14295776 0.1454929 0.09120406
## oPO4 PO4 Chla
## mxPH 0.09022909 0.1013296 0.43182377
## mnO2 -0.39375269 -0.4639607 -0.13121671
## Cl 0.37925596 0.4451912 0.14295776
## NO3 0.13301452 0.1570297 0.14549290
## NH4 0.21931121 0.1993958 0.09120406
## oPO4 1.00000000 0.9119646 0.10691478
## PO4 0.91196460 1.0000000 0.24849223
## Chla 0.10691478 0.2484922 1.00000000
algae_pca <- prcomp(numericAlgaeData,scale = TRUE)
algae_pca
## Standard deviations (1, .., p=8):
## [1] 1.6534534 1.3228050 1.1314561 0.8800021 0.8182890 0.7177949 0.4570020
## [8] 0.2607780
##
## Rotation (n x k) = (8 x 8):
## PC1 PC2 PC3 PC4 PC5
## mxPH 0.1229044 -0.41654322 0.561511592 0.04183663 -0.077012393
## mnO2 -0.3406130 0.24345520 0.224488272 0.45242066 -0.717115848
## Cl 0.3710606 -0.06688890 -0.004180915 0.80702475 0.381375926
## NO3 0.2234969 0.61831159 0.247678574 0.12982214 0.044840756
## NH4 0.2521532 0.58568950 0.147954838 -0.27347425 0.123589856
## oPO4 0.5157449 -0.07397518 -0.261019584 -0.05962805 -0.455432104
## PO4 0.5469393 -0.10037673 -0.187249761 -0.05833390 -0.331087209
## Chla 0.2291809 -0.14784435 0.669225868 -0.20898804 -0.006638359
## PC6 PC7 PC8
## mxPH 0.68712332 -0.11191985 0.06119847
## mnO2 -0.05369360 0.21785668 0.07094528
## Cl -0.06828080 0.23437668 -0.03861628
## NO3 0.02110287 -0.69577863 -0.05456656
## NH4 0.31297699 0.61468449 0.07511114
## oPO4 0.09139452 0.02136500 -0.66379242
## PO4 -0.11552993 -0.07266973 0.72392668
## Chla -0.63262645 0.13190038 -0.12814403
summary(algae_pca)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 1.6535 1.3228 1.1315 0.8800 0.8183 0.7178 0.45700
## Proportion of Variance 0.3417 0.2187 0.1600 0.0968 0.0837 0.0644 0.02611
## Cumulative Proportion 0.3417 0.5605 0.7205 0.8173 0.9010 0.9654 0.99150
## PC8
## Standard deviation 0.2608
## Proportion of Variance 0.0085
## Cumulative Proportion 1.0000
plot(algae_pca)
algaeDataset$a1Cat[algaeDataset$a1<=4.85] = "Less"
algaeDataset$a1Cat[algaeDataset$a1>4.85] = "More"
algaeDataset$a2Cat[algaeDataset$a2<=3.6] = "Less"
algaeDataset$a2Cat[algaeDataset$a2>3.6] = "More"
algaeDataset$a3Cat[algaeDataset$a3<=1.70] = "Less"
algaeDataset$a3Cat[algaeDataset$a3>1.70] = "More"
algaeDataset$a4Cat[algaeDataset$a4<=1.846] = "Less"
algaeDataset$a4Cat[algaeDataset$a4>1.846] = "More"
algaeDataset$a5Cat[algaeDataset$a5<=2.650] = "Less"
algaeDataset$a5Cat[algaeDataset$a5>2.650] = "More"
algaeDataset$a6Cat[algaeDataset$a6<=6.447] = "Less"
algaeDataset$a6Cat[algaeDataset$a6>6.447] = "More"
algaeDataset$a7Cat[algaeDataset$a7<=1.00] = "Less"
algaeDataset$a7Cat[algaeDataset$a7>1.00] = "More"
Let us find out eigen values:
eigen_algaes <- algae_pca$sdev^2
eigen_algaes
## [1] 2.73390819 1.74981296 1.28019290 0.77440364 0.66959688 0.51522950
## [7] 0.20885079 0.06800514
names(eigen_algaes) <- paste("PC",1:8,sep="")
eigen_algaes
## PC1 PC2 PC3 PC4 PC5 PC6
## 2.73390819 1.74981296 1.28019290 0.77440364 0.66959688 0.51522950
## PC7 PC8
## 0.20885079 0.06800514
sumlambdas_algaes <- sum(eigen_algaes)
sumlambdas_algaes
## [1] 8
propvar_algaes <- eigen_algaes/sumlambdas_algaes
propvar_algaes
## PC1 PC2 PC3 PC4 PC5 PC6
## 0.341738523 0.218726620 0.160024113 0.096800454 0.083699610 0.064403688
## PC7 PC8
## 0.026106349 0.008500642
cumvar_algaes <- cumsum(propvar_algaes)
cumvar_algaes
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## 0.3417385 0.5604651 0.7204893 0.8172897 0.9009893 0.9653930 0.9914994
## PC8
## 1.0000000
matlambdas_algaes <- rbind(eigen_algaes,propvar_algaes,cumvar_algaes)
matlambdas_algaes
## PC1 PC2 PC3 PC4 PC5
## eigen_algaes 2.7339082 1.7498130 1.2801929 0.77440364 0.66959688
## propvar_algaes 0.3417385 0.2187266 0.1600241 0.09680045 0.08369961
## cumvar_algaes 0.3417385 0.5604651 0.7204893 0.81728971 0.90098932
## PC6 PC7 PC8
## eigen_algaes 0.51522950 0.20885079 0.068005139
## propvar_algaes 0.06440369 0.02610635 0.008500642
## cumvar_algaes 0.96539301 0.99149936 1.000000000
rownames(matlambdas_algaes) <- c("Eigenvalues","Prop. variance","Cum. prop. variance")
round(matlambdas_algaes,4)
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Eigenvalues 2.7339 1.7498 1.2802 0.7744 0.6696 0.5152 0.2089
## Prop. variance 0.3417 0.2187 0.1600 0.0968 0.0837 0.0644 0.0261
## Cum. prop. variance 0.3417 0.5605 0.7205 0.8173 0.9010 0.9654 0.9915
## PC8
## Eigenvalues 0.0680
## Prop. variance 0.0085
## Cum. prop. variance 1.0000
attach(algaeDataset)
algae_pca$rotation
## PC1 PC2 PC3 PC4 PC5
## mxPH 0.1229044 -0.41654322 0.561511592 0.04183663 -0.077012393
## mnO2 -0.3406130 0.24345520 0.224488272 0.45242066 -0.717115848
## Cl 0.3710606 -0.06688890 -0.004180915 0.80702475 0.381375926
## NO3 0.2234969 0.61831159 0.247678574 0.12982214 0.044840756
## NH4 0.2521532 0.58568950 0.147954838 -0.27347425 0.123589856
## oPO4 0.5157449 -0.07397518 -0.261019584 -0.05962805 -0.455432104
## PO4 0.5469393 -0.10037673 -0.187249761 -0.05833390 -0.331087209
## Chla 0.2291809 -0.14784435 0.669225868 -0.20898804 -0.006638359
## PC6 PC7 PC8
## mxPH 0.68712332 -0.11191985 0.06119847
## mnO2 -0.05369360 0.21785668 0.07094528
## Cl -0.06828080 0.23437668 -0.03861628
## NO3 0.02110287 -0.69577863 -0.05456656
## NH4 0.31297699 0.61468449 0.07511114
## oPO4 0.09139452 0.02136500 -0.66379242
## PO4 -0.11552993 -0.07266973 0.72392668
## Chla -0.63262645 0.13190038 -0.12814403
print(algae_pca)
## Standard deviations (1, .., p=8):
## [1] 1.6534534 1.3228050 1.1314561 0.8800021 0.8182890 0.7177949 0.4570020
## [8] 0.2607780
##
## Rotation (n x k) = (8 x 8):
## PC1 PC2 PC3 PC4 PC5
## mxPH 0.1229044 -0.41654322 0.561511592 0.04183663 -0.077012393
## mnO2 -0.3406130 0.24345520 0.224488272 0.45242066 -0.717115848
## Cl 0.3710606 -0.06688890 -0.004180915 0.80702475 0.381375926
## NO3 0.2234969 0.61831159 0.247678574 0.12982214 0.044840756
## NH4 0.2521532 0.58568950 0.147954838 -0.27347425 0.123589856
## oPO4 0.5157449 -0.07397518 -0.261019584 -0.05962805 -0.455432104
## PO4 0.5469393 -0.10037673 -0.187249761 -0.05833390 -0.331087209
## Chla 0.2291809 -0.14784435 0.669225868 -0.20898804 -0.006638359
## PC6 PC7 PC8
## mxPH 0.68712332 -0.11191985 0.06119847
## mnO2 -0.05369360 0.21785668 0.07094528
## Cl -0.06828080 0.23437668 -0.03861628
## NO3 0.02110287 -0.69577863 -0.05456656
## NH4 0.31297699 0.61468449 0.07511114
## oPO4 0.09139452 0.02136500 -0.66379242
## PO4 -0.11552993 -0.07266973 0.72392668
## Chla -0.63262645 0.13190038 -0.12814403
algaetyp_pca <- cbind(data.frame(a1Cat),algae_pca$x)
algaetyp_pca
## a1Cat PC1 PC2 PC3 PC4 PC5
## 1 Less 0.820687351 0.28952661 1.247077898 0.10280148 -0.258871961
## 2 Less 3.730027226 -1.25263632 -1.919915169 -0.27643930 -2.447314074
## 3 Less 0.173728419 0.40219049 0.223270034 0.39055864 -1.078906577
## 4 Less 0.464201113 -0.65403533 -0.860002099 -0.07044543 1.590370250
## 5 More 0.090824457 1.11267251 0.418767667 0.52084488 0.381573327
## 6 More -0.594295147 1.14812498 1.729132129 1.28066393 -0.492580725
## 7 Less -0.461845357 -0.27379594 -0.201312021 0.86610489 -0.034500048
## 8 More -0.626870183 0.45685288 0.155396725 0.76133867 -0.008336383
## 9 More -0.070006256 -1.45557256 -0.020718879 -1.27202952 1.734070270
## 10 More -1.490732163 0.01488890 -0.400514057 -0.26213845 -0.081104340
## 11 More -1.773498154 0.30642031 -0.558065117 -0.20267156 0.007206828
## 12 More -2.063592422 0.69122272 -0.710360856 0.07556950 -0.377940602
## 13 More -1.284076861 -0.12195696 0.749976035 -0.78668971 0.152078804
## 14 More -2.022716140 0.44405111 -0.400251269 0.07418711 -0.489111165
## 15 More -1.508616028 0.04241445 -0.455218138 -0.40285710 0.007547931
## 16 More -1.750959363 0.48439613 -0.707361393 -0.06688095 -0.542181230
## 17 More -1.859573702 0.37619460 -0.349979959 0.10016219 -0.654858803
## 18 More -1.558924415 0.30456846 -0.794496754 -0.32440504 0.001968922
## 19 More -1.553736415 0.62088190 -1.081874966 -0.24748378 -0.245324287
## 20 Less 7.138933614 1.11883370 -2.910237166 -2.41808400 -1.560931436
## 21 Less 4.321121136 0.23346476 -1.628006760 0.45028750 -3.063291345
## 22 More -1.861881449 0.53500147 -1.312069945 -0.59356919 0.314918126
## 23 More -1.317455922 0.40148368 -0.212008845 0.21158529 0.121220049
## 24 More -1.504799434 0.27945011 -0.739151499 -0.48786985 0.601922799
## 25 More -1.688033251 0.10219781 -0.404020313 -0.28571424 0.317468724
## 26 Less -1.541335712 0.65894025 -0.219973765 0.02152859 -0.128086971
## 27 More -1.737037580 0.68325415 -1.423821602 -0.53961478 0.725662967
## 29 More -1.445319496 -0.16739228 -0.362534668 -0.16005154 0.005556208
## 30 More -2.129119162 0.68333377 -1.131755757 -0.07546667 -0.231507386
## 31 Less -1.138986912 0.92414223 -0.790507510 0.20875880 -1.168907985
## 32 More 1.114558776 -0.11276569 -0.929457075 -0.06821939 -1.787575174
## 33 Less -0.971587476 0.40434746 -0.347890921 0.13920528 -0.701575197
## 34 More -0.663148571 0.79627656 0.572846593 -0.20159175 0.321024056
## 35 More -0.430903114 1.13516793 0.279977741 -1.14638993 1.192347941
## 36 More -0.187621137 -0.01155591 0.545059307 -0.34711322 0.315239228
## 37 More -1.960674027 -0.24455929 0.208120214 -0.13908162 -0.263869000
## 39 Less 0.939939183 -0.42364707 -0.305415151 -0.48420743 -1.070843115
## 40 Less 0.597687584 0.03709817 -0.430071193 -0.10107442 -1.431117519
## 41 Less 1.717866799 -0.11335242 -1.018455972 0.02454441 0.625782296
## 42 Less 0.410827844 -0.17001855 -0.068685335 -0.18819564 0.666982561
## 43 Less 2.500527310 -0.01215446 -0.091926493 -0.20388085 -0.998603006
## 44 Less 2.204181663 0.05437041 -0.397058522 0.16357712 -1.312247104
## 45 More -1.276339429 0.37605049 0.844101120 1.57974096 -0.562597024
## 46 More -0.922866667 0.38335662 0.586808873 1.70402881 -0.226304823
## 47 More -1.233487853 0.61905826 0.128981677 1.26876546 -0.162316227
## 49 More -1.044407738 0.46374216 -0.756408757 -0.23183829 -0.050409174
## 50 More -1.726254795 0.92417537 -0.480807899 0.05113386 -0.134157800
## 51 Less -1.213435785 0.81114472 -0.283245017 0.19584731 0.189703855
## 52 More -1.189658195 -0.22102299 -0.274303607 -0.31094607 0.821181240
## 53 More -1.939066120 0.16888167 -0.250982622 -0.06710562 -0.235296021
## 54 More -1.665897539 -0.07272219 -0.446695022 -0.47307558 0.344887705
## 64 More -2.054129845 0.45478573 -0.619630151 -0.16062891 -0.092760343
## 65 More -2.253602251 0.96752710 -0.986227813 -0.03151039 -0.293043131
## 66 More -2.039839003 0.43245399 -0.878346158 -0.33980835 0.123258613
## 67 More -2.022885433 0.67347035 -1.197598498 -0.43349745 0.253757140
## 68 More -2.423826500 1.09630468 -1.187073416 0.01736963 -0.387226394
## 69 Less 2.396058237 -0.62529207 -2.311200714 -2.01946494 1.031175124
## 70 Less 2.103452475 -0.26574628 -2.435357007 -1.98050566 1.118372307
## 71 More 1.166055264 0.11804099 -0.920102542 -0.97069899 -0.100851747
## 72 More -0.084405646 -0.38604405 0.222612389 -0.08501933 0.288110480
## 73 Less -0.545247770 1.15923158 0.379295588 0.34932510 -0.034235934
## 74 Less 1.679706914 -0.44138892 -0.147335376 1.28796552 0.441990295
## 75 Less 1.454019074 -0.61810400 -0.309737593 1.03200075 0.979245884
## 76 Less 0.563207609 -0.80437748 1.357447454 0.05130933 -0.578323452
## 77 More -0.985444107 -0.19144233 -0.182549613 0.01721149 -0.026355390
## 78 More -0.451382035 -0.61572372 -0.762262786 -0.76927453 1.061126131
## 79 More -0.057493028 -0.88650776 -1.019382662 -1.27915210 1.810277821
## 80 More -1.095362279 0.60251012 -0.918970515 -0.36136616 0.095532396
## 81 More -1.333419609 0.80902589 -0.912305891 -0.27255717 0.013280173
## 82 Less -1.666303670 1.32774351 -0.604966779 0.13177256 -0.401139186
## 83 More -0.721719240 0.86210906 -0.274927183 -0.51737237 0.246078010
## 84 More -1.337396983 1.35655572 -0.571814453 0.11279506 -0.362639860
## 85 Less -0.083256508 0.93292798 -0.994443739 0.11449513 -0.856226549
## 86 Less 1.113020956 0.20839951 -1.442137565 -0.49765490 0.504473199
## 87 Less -0.627041622 0.88931399 -0.956174214 0.26053208 -0.435938616
## 88 Less 5.109797276 0.73973250 -2.342805969 -1.98094426 -0.806423253
## 89 Less 3.581271226 1.61851580 -1.509671936 -0.39707768 -2.025972681
## 90 Less 2.402067939 -0.99370001 0.749068559 0.99448125 -0.309143639
## 91 Less 3.042285366 -1.09613072 -0.504255215 2.26730749 -0.755262912
## 92 Less 1.246390505 0.04440299 -0.475083245 1.20411612 -0.971532136
## 93 Less 1.168284761 -0.77565430 1.210789026 -0.01329431 -0.335906293
## 94 Less 0.534300461 -0.01010609 -0.777160489 0.67564889 -0.804692423
## 95 Less 0.418246779 0.47850635 -0.460533973 0.92400860 -1.235081620
## 96 More -0.485970670 -0.81981847 0.817299198 0.42738472 -0.178995237
## 97 Less 1.873365557 -2.42670320 2.377118266 -1.01989963 0.596517542
## 98 Less 2.171759680 -2.51278222 2.950457655 -1.53709532 0.906876220
## 99 Less 0.743301691 -0.15264300 -0.864507879 0.63487946 1.266562174
## 100 More 0.620426701 0.44884728 0.062924444 0.55428841 0.709115650
## 101 More 0.330043641 -0.15424273 -0.062471765 -0.17733798 0.893576720
## 102 More 0.062065662 -0.16969621 -0.756282343 0.28572965 1.373754735
## 103 More 0.583611920 -0.22787570 -0.709759736 -0.40908956 1.356880437
## 104 More 0.961347019 1.32445648 -0.999963449 0.31555502 -0.156594157
## 105 More 0.924877797 0.25710430 1.565810776 -0.34402721 -0.347680994
## 106 More 0.102539738 -0.95199032 0.195819990 -0.04613245 0.486992618
## 107 More 0.893910241 0.85421591 1.658577038 0.04134692 -0.722587146
## 108 More -0.462914504 0.39204247 0.686187798 0.38621562 -0.394128181
## 109 Less 0.472041799 -0.73299688 0.528640497 -0.76721331 0.900963026
## 110 Less -0.337791385 0.51190216 0.512384107 0.26564082 -0.643848965
## 111 More -1.498297912 -0.60079892 0.618051527 -0.22763026 -0.028263229
## 112 More -1.802502017 0.03828850 0.155759881 0.05356390 -0.386534295
## 113 More -1.783162847 -0.15500168 0.630342193 0.13924399 -0.557736446
## 114 Less -0.358145368 -0.51271408 -1.077150953 -0.31302484 1.269402695
## 115 More -0.828182432 -0.28038142 -0.397626764 0.45431446 0.220844403
## 117 More -1.833557350 -0.51270813 0.589300195 -0.01110539 -0.641268448
## 118 More -1.937213785 -0.21738427 0.349626478 0.03456519 -0.471667866
## 119 Less 3.182807746 -1.18676557 -0.530592652 -0.44889821 -0.361445212
## 120 Less 2.593888375 -0.68644148 -1.006134281 1.01818389 0.154058292
## 121 Less 1.092425151 0.35077618 -0.110998005 0.17826168 -0.779908089
## 122 Less 1.319525062 -0.26362356 -0.387845066 -0.41925237 -0.193745160
## 123 Less 0.981747784 0.28900430 -0.443339059 0.19995658 -0.653311104
## 124 More -1.219868806 0.62831948 -0.875258977 -0.17897218 -0.425385259
## 125 Less -0.725132657 -0.35616208 -0.007866780 -0.31756837 -0.428326564
## 126 Less -0.950094292 -0.42794209 0.410308309 -0.01683774 -0.669086036
## 127 Less 1.148682378 -1.06272515 3.868961232 -0.37809053 -1.307801327
## 128 Less 2.107548021 -2.03165410 3.771833103 -1.62304786 -0.171711639
## 129 Less 0.297479224 -0.43381555 1.508818718 -0.36613620 -0.550400467
## 130 Less -1.052942550 -0.51630224 0.590837531 -0.27934429 -0.303725317
## 131 Less -0.780133616 -0.59131317 -0.242412756 -0.66862957 0.336978483
## 132 Less -1.472956115 0.59893788 -1.096394307 -0.21313538 -0.284486748
## 133 Less 1.391890582 1.37986781 0.423796337 2.42000161 1.426695912
## 134 Less 4.076414300 -0.17566595 -0.942395685 5.85120866 2.172889797
## 135 More -0.001571725 0.76346167 0.134864415 2.28445355 0.044877500
## 136 More 0.693303822 0.15916102 -0.806999053 0.05452838 -0.798327812
## 137 Less -0.944460716 0.55370758 0.143369648 0.63487674 -0.590168352
## 138 More -0.702692311 -0.66152476 0.410572587 0.10823461 -0.127020471
## 139 More -0.292279487 -0.71203382 -0.711413733 -0.50611525 0.949203047
## 140 Less -0.118406575 1.45335424 0.152734193 0.79387559 -0.445169419
## 141 Less 0.939080291 -0.17202292 -0.627636517 -0.29527577 0.490542870
## 142 More -1.550208789 0.15736608 -0.520054220 -0.32830271 0.147223443
## 143 More -1.674792127 0.30376197 -0.192709460 -0.09178828 -0.077962200
## 144 Less 1.502675930 0.49201120 -0.004135168 -0.20952333 1.625328065
## 145 Less 0.747312382 1.08672547 -0.804845340 0.44193536 1.240817490
## 146 More 1.178401834 1.04370285 -0.475602931 -0.19723426 0.911488102
## 147 More -0.108266124 -0.70956873 0.599128948 -0.37864511 0.385688498
## 148 More -0.682681571 -0.45539990 0.765961553 0.04464203 0.022731065
## 149 More -0.387030827 -0.58897790 0.261465412 0.17242454 0.138507214
## 150 Less 1.018009135 -1.47610751 0.234817991 -0.97026428 0.866556576
## 151 Less -0.659354777 -0.78549321 1.530366185 0.37438475 -0.412233605
## 152 Less 0.084501862 -0.39210678 -0.711024070 -0.71013086 1.816715474
## 153 Less 4.532049054 14.32540477 5.303035226 -1.64016350 1.657671115
## 154 Less 0.235692820 -0.30104499 -0.716571703 1.05011463 2.004048710
## 155 Less -0.256625901 0.64020389 0.661049022 1.22782900 0.557428468
## 156 More 2.916449864 -0.34974299 -0.838122754 -0.61598249 1.197027546
## 157 More 2.130700135 0.03837477 -1.152020789 -0.75158213 0.561862991
## 158 Less 0.642893835 -1.67117559 0.418402654 -1.03908076 1.679079935
## 159 Less -1.129784345 -0.42242693 0.907192758 -0.10359892 -0.262299001
## 160 Less -0.918932737 -0.35548189 1.291995235 0.02311793 -0.565327232
## 162 More 2.353274784 -2.94920231 3.420526920 -1.48793359 0.030585864
## 163 More 1.945165085 -2.05350090 2.733964364 -0.99391716 -0.976994772
## 164 Less -0.618524420 -1.18261165 3.647178495 0.13901906 -0.776877205
## 165 Less -1.275888269 1.10627010 -0.905536604 -0.10045161 0.095106152
## 166 Less -0.584243754 1.10229877 -0.877411181 0.07371001 -0.562772583
## 167 Less 1.995699313 -2.33335747 1.726170821 -0.64777787 1.139946228
## 168 Less -0.049775043 -0.62677063 0.827110334 0.65363512 -0.614424933
## 169 More 1.448096292 -0.51768836 0.071277302 -0.17065506 -0.940156748
## 170 Less 1.010937356 -0.07804698 -0.781651952 -0.27739762 -0.634350268
## 171 Less 2.430073914 -0.57260265 -0.433708192 0.02491070 0.190600932
## 172 Less 3.712418313 -0.38321604 -1.794582123 1.04311751 -0.160836183
## 173 Less 0.464709592 -0.16794450 -0.134201587 1.23861137 0.289836615
## 174 Less 0.288264865 -0.80815942 0.152630037 0.26334806 0.711916445
## 175 Less 1.627966953 -0.60390431 1.157094172 3.05941994 0.589218406
## 176 Less 2.538557432 -1.65668036 0.761939460 1.93219538 1.166398379
## 177 More -1.619529803 -0.61666512 0.642560937 -0.10581612 -0.356599227
## 178 More -1.849843018 -0.06543619 -0.060862670 -0.15991163 -0.224947833
## 179 More -1.706948653 -0.36521502 0.275844002 -0.18549443 -0.118342389
## 180 More -1.728060965 -0.61631293 0.511793686 -0.26296819 -0.086344704
## 181 More -1.752124512 -0.31897537 -0.036809749 -0.40409097 0.157837547
## 182 More -1.762636719 -0.49430472 0.522054645 -0.21107778 -0.189329458
## 183 More -1.692748425 -0.34617629 0.190330612 -0.29633518 -0.027033366
## 185 More -1.491808954 -0.22004337 -0.180072452 -0.23886639 -0.221151938
## 186 Less 0.839501990 -0.33522787 1.930893979 0.05078490 -1.019334849
## 187 Less -0.852262903 -0.26397496 1.295819266 0.26208640 -0.767484576
## 188 Less -0.458499580 -0.50954642 0.427743048 -0.41398657 0.264963069
## 189 Less -0.727049151 -0.32588686 1.003057318 0.07591429 -0.607220352
## 190 Less -0.208859019 -0.90203717 0.696134011 -0.84390815 0.225864224
## 191 More -1.134051552 -0.41530241 0.810063363 0.16538221 -0.702743225
## 192 Less -1.347736567 -0.35827330 0.485644698 -0.11243687 -0.272879738
## 193 Less -0.885300638 -0.52976836 -0.202438563 -0.65919568 0.221423609
## 194 Less -0.658302683 -0.30048567 1.228998039 0.09462446 -0.625366137
## 195 More -0.865656658 -0.52419201 0.352810976 -0.54025837 0.477228930
## 196 More -0.626832428 -0.21092010 0.108468626 -0.31808793 0.182800955
## 197 More -1.111432040 0.01581517 0.291477332 -0.00316459 -0.386780238
## 198 Less 1.159800412 -0.77464689 0.486146403 1.13152911 1.328521400
## 200 Less 0.585070923 -0.91737958 0.402755888 0.26822661 0.975991531
## PC6 PC7 PC8
## 1 -1.254907054 -1.036429e-01 -0.3275141504
## 2 0.732427362 3.804146e-05 -0.1031313881
## 3 -0.076327992 -2.217242e-01 -0.0810449028
## 4 0.341182442 -2.375011e-01 0.0041561220
## 5 0.079724465 -1.298963e+00 -0.2314477640
## 6 -0.287807382 -5.217429e-01 -0.1269138264
## 7 0.306636141 3.890078e-01 0.0282665027
## 8 0.107243324 -1.826340e-01 -0.1063137117
## 9 1.270158158 -4.746347e-01 -0.1172808967
## 10 0.172578749 8.779985e-02 -0.0668006746
## 11 -0.157149568 1.608981e-01 -0.1301719675
## 12 -0.550176227 3.467045e-01 -0.1135584874
## 13 -1.334280508 4.020799e-01 -0.4055698773
## 14 -0.145922531 3.006561e-01 -0.1323610380
## 15 0.137488919 2.969272e-02 0.1146390613
## 16 -0.489141813 2.891875e-01 0.3876250674
## 17 -0.107632482 3.097730e-01 0.0557631250
## 18 -0.290372830 1.373047e-01 0.0072268528
## 19 -0.672826443 2.147590e-01 -0.1480937507
## 20 1.161968527 1.930351e+00 0.1665028467
## 21 -0.345585384 3.837402e-01 -0.3332761717
## 22 -0.833763375 3.303265e-01 -0.2378939443
## 23 -0.338147073 6.844367e-02 -0.1187097917
## 24 -0.255335538 6.783754e-02 -0.0875373681
## 25 0.035627564 7.791411e-02 -0.1245404079
## 26 -0.147195376 -2.161710e-01 0.0008930389
## 27 -1.000834126 1.490909e-01 -0.2402955686
## 29 0.263962334 2.254023e-01 -0.0574232663
## 30 -0.893184295 6.456065e-01 -0.1440778057
## 31 -0.814997769 1.251057e-01 0.0999310951
## 32 0.329631468 -3.208749e-01 -0.2164692745
## 33 -0.255919117 1.716256e-02 0.1820218302
## 34 1.312823035 9.214440e-01 0.1267816733
## 35 1.660109355 2.107273e+00 0.1625983252
## 36 1.451347514 1.028163e-01 -0.0253343621
## 37 0.729230853 1.911761e-01 -0.0312418505
## 39 0.383485172 -3.258795e-01 -0.2068493965
## 40 0.139057093 -2.848163e-01 -0.0636953072
## 41 0.117468464 -8.877048e-01 0.2394887647
## 42 0.130356195 -2.157562e-01 0.2418854623
## 43 0.039870344 -1.224840e+00 -0.3857006970
## 44 0.362110465 -1.040699e+00 -0.4652684827
## 45 0.603197162 6.133331e-02 0.0740237004
## 46 0.484955277 2.682411e-02 -0.0867741371
## 47 0.158839713 7.595163e-03 -0.0457629723
## 49 -0.426700450 -1.374626e-01 0.2604255624
## 50 -1.133163248 1.986987e-01 -0.2557299821
## 51 -0.542728240 -1.478238e-01 -0.0833723344
## 52 0.182163210 -2.127183e-02 -0.1485965826
## 53 0.129008583 2.414191e-01 -0.0867157647
## 54 0.167699580 1.098680e-01 -0.1514266303
## 64 -0.360107232 2.956661e-01 -0.1244846608
## 65 -0.889526818 4.527730e-01 -0.1426070200
## 66 -0.523262826 3.266177e-01 -0.1518943950
## 67 -1.016884174 3.545495e-01 -0.1868790112
## 68 -1.199822067 5.361717e-01 -0.1786640136
## 69 -0.460904065 -1.416675e-02 -0.0672963441
## 70 -0.051545351 1.476308e-01 -0.1104692654
## 71 -0.124902621 5.599780e-01 0.2268565708
## 72 0.832040799 -4.625342e-01 0.3406702659
## 73 -0.141921338 -1.033940e+00 -0.3842066387
## 74 -0.375336957 2.082403e-01 -0.0029130604
## 75 0.034012413 7.303707e-02 0.2094190562
## 76 1.230291098 -7.337531e-01 0.4138074088
## 77 0.285013991 2.164527e-01 0.2539209886
## 78 0.238797316 -5.486445e-02 0.0773366189
## 79 0.298436097 -2.729065e-01 0.0252916542
## 80 -0.488600692 -2.060131e-01 0.1765749823
## 81 -0.588265214 -3.166961e-02 -0.1912985994
## 82 -0.887833220 -1.745168e-01 0.0281804380
## 83 -1.226518905 -4.423500e-01 -0.0311395237
## 84 -0.682753342 -4.841471e-01 -0.0837758811
## 85 -0.510540493 4.078020e-03 0.1929673188
## 86 -0.320235349 -1.777436e-01 0.0923933802
## 87 -0.736378633 9.459540e-02 0.3032354623
## 88 0.731352949 8.074608e-01 0.2333123015
## 89 -0.164143405 3.396104e-01 1.2934217137
## 90 -0.392645851 1.775039e-01 -0.1877696651
## 91 0.934296228 2.466780e-01 0.0533811673
## 92 0.081461034 -4.216018e-02 -0.1272306065
## 93 0.422305876 -5.507839e-01 0.1032443598
## 94 -0.416894646 2.899443e-01 0.0852409918
## 95 -0.155305287 -8.334673e-02 -0.1281615676
## 96 0.233693056 5.809688e-01 0.4266526380
## 97 -0.424093371 2.675838e-01 0.0016848314
## 98 -1.509245391 4.111979e-01 -0.1815478204
## 99 -0.045929581 -2.595798e-01 0.4251127693
## 100 -0.804119065 -3.394208e-01 0.5127511323
## 101 -1.188590620 -1.350729e-03 0.3448048111
## 102 -0.257290802 -9.569788e-03 0.4239992132
## 103 -0.689613758 -1.137877e-01 0.2068435850
## 104 -0.559132952 -8.481183e-01 0.5407136652
## 105 -2.821062479 9.495555e-02 0.6031382872
## 106 1.092212254 -3.531988e-01 0.7896381488
## 107 -2.374251082 -5.064052e-01 0.4907513739
## 108 0.354851559 6.620927e-03 0.2503257925
## 109 0.251246494 -1.246063e-01 0.0055233242
## 110 0.062615025 -3.191079e-01 0.0134918497
## 111 1.309873286 -1.128868e-01 -0.0078261452
## 112 0.554908370 6.898068e-02 0.0403497925
## 113 0.961419785 1.440636e-01 0.0227996411
## 114 -0.035923082 1.807324e-01 0.0177898104
## 115 0.139076733 5.260945e-01 0.0591316413
## 117 1.113804566 2.455637e-01 0.0022992057
## 118 0.605664713 2.978337e-01 0.0104779826
## 119 0.028843446 -5.270954e-01 0.1072713916
## 120 0.264832291 -2.031879e-01 -0.2810193777
## 121 0.223465495 -8.248062e-01 0.3075288939
## 122 -0.107448286 -6.631532e-01 -0.0971992949
## 123 0.247921314 -7.650413e-01 -0.3262196395
## 124 -0.799579750 2.068535e-01 0.2035880208
## 125 0.547718199 -9.124416e-02 0.1461069331
## 126 1.089593447 -1.256524e-01 0.0091673710
## 127 -1.052509684 -7.218260e-02 0.6520456853
## 128 -1.767568873 5.449313e-03 0.0097528659
## 129 -0.907385262 -1.180946e-02 0.0103275539
## 130 0.691534462 1.187478e-01 0.0493232893
## 131 0.723260683 -1.347000e-01 -0.0393252102
## 132 -0.824725674 3.458857e-01 -0.1859735885
## 133 -0.149381975 1.164845e+00 0.4806626381
## 134 -0.553650149 1.049144e+00 -0.0423145869
## 135 0.007468407 9.863990e-03 -0.3208140555
## 136 0.252951952 -4.753443e-01 -0.3678737745
## 137 0.297473344 -3.186678e-01 0.0027598934
## 138 0.476808917 2.872626e-01 0.2630721129
## 139 0.419092941 1.446609e-02 -0.1184623885
## 140 -0.030724026 -9.481997e-01 0.0605133218
## 141 0.280790279 -7.115468e-01 -0.1807377792
## 142 -0.008787010 4.749768e-02 -0.0888962427
## 143 0.103527359 5.131972e-02 -0.0807659355
## 144 -0.201867693 -1.106181e+00 0.0891031469
## 145 -0.369311493 -1.262815e+00 -0.1912801448
## 146 -0.095224398 -5.265474e-01 0.8490330200
## 147 -0.360817115 2.215596e-01 0.0002232531
## 148 -0.035974046 3.295716e-01 -0.0715176794
## 149 0.695194193 -2.779100e-02 0.1387515830
## 150 -0.099697539 3.932585e-02 -0.1565618790
## 151 0.786122082 1.162813e-01 -0.0266310253
## 152 -0.628856008 -2.124479e-01 0.0248272164
## 153 1.502409582 2.723081e-01 -0.3774853945
## 154 0.008433250 1.505163e-01 -0.1390983703
## 155 -0.916833338 2.279070e-01 -0.2596300123
## 156 -0.801217938 -3.125560e-01 0.1640235078
## 157 -0.685583058 1.382482e-01 -0.8448194554
## 158 0.386325517 -8.047875e-02 -0.0937460783
## 159 0.208734699 1.981433e-01 -0.0261629190
## 160 -0.421021020 3.710247e-01 -0.0697303935
## 162 -0.445744514 3.056452e-01 -0.3151937467
## 163 -1.494337654 7.196649e-01 -0.4233680361
## 164 -1.154302648 9.511764e-01 -0.2575447687
## 165 -0.807523716 -3.265073e-01 0.0980454931
## 166 -0.745555826 -3.363478e-01 0.2273177465
## 167 0.145718774 7.221717e-02 0.0384099343
## 168 0.305071514 4.260211e-01 0.0264092174
## 169 0.756649520 -2.537995e-01 -0.4249850838
## 170 0.313089788 -1.779824e-01 -0.4725689619
## 171 0.160084703 1.171689e-01 -0.5567573363
## 172 0.072193615 2.537738e-01 -0.6898088438
## 173 0.280928028 8.606759e-03 0.0970974588
## 174 0.671409039 -1.367648e-01 0.0557193346
## 175 -0.021334113 6.023453e-01 0.0671180660
## 176 1.005588912 1.156397e-01 -0.2900808653
## 177 1.285263486 6.267489e-02 0.0036975951
## 178 0.431668081 1.825752e-01 -0.1063498524
## 179 0.867184070 9.718564e-02 -0.0252720909
## 180 1.145609839 6.976201e-02 -0.0117173938
## 181 0.592966482 1.061863e-01 -0.0870035693
## 182 0.906409226 1.330135e-01 -0.0337690997
## 183 0.658610833 1.161975e-01 -0.0364173668
## 185 0.370739768 2.089839e-01 0.0072082456
## 186 -0.220220861 -4.692873e-01 0.1493992369
## 187 0.716806636 -1.715167e-01 0.0552067301
## 188 0.437587059 -2.705809e-01 -0.1192106616
## 189 0.473754482 -9.207575e-02 0.0755528785
## 190 0.261493049 -2.000912e-01 0.0602616454
## 191 1.095277800 -4.634807e-02 0.1751504592
## 192 0.607176270 9.026465e-02 0.0378389680
## 193 0.398498631 -6.990289e-02 0.3729223930
## 194 0.385905916 -1.344080e-01 -0.0501557016
## 195 0.872699380 -3.688906e-01 0.0386993640
## 196 0.850737608 -5.304535e-01 -0.1021178178
## 197 0.576072118 -1.834781e-01 0.0575075110
## 198 -0.543092675 3.102720e-01 -0.2826833771
## 200 0.382534236 -1.415542e-01 -0.0150786289
algaetyp_pca2 <- cbind(data.frame(a2Cat),algae_pca$x)
algaetyp_pca3 <- cbind(data.frame(a3Cat),algae_pca$x)
algaetyp_pca4 <- cbind(data.frame(a4Cat),algae_pca$x)
algaetyp_pca5 <- cbind(data.frame(a5Cat),algae_pca$x)
algaetyp_pca6 <- cbind(data.frame(a6Cat),algae_pca$x)
algaetyp_pca7 <- cbind(data.frame(a7Cat),algae_pca$x)
T-test for PCA:
library(car)
## Loading required package: carData
t.test(PC1~algaeDataset$a1Cat,data=algaetyp_pca)
##
## Welch Two Sample t-test
##
## data: PC1 by algaeDataset$a1Cat
## t = 7.8119, df = 161.94, p-value = 6.696e-13
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 1.234850 2.070354
## sample estimates:
## mean in group Less mean in group More
## 0.826301 -0.826301
t.test(PC2~algaeDataset$a1Cat,data=algaetyp_pca)
##
## Welch Two Sample t-test
##
## data: PC2 by algaeDataset$a1Cat
## t = -0.6213, df = 119.51, p-value = 0.5356
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.5082051 0.2654453
## sample estimates:
## mean in group Less mean in group More
## -0.06068993 0.06068993
t.test(PC3~algaeDataset$a1Cat,data=algaetyp_pca)
##
## Welch Two Sample t-test
##
## data: PC3 by algaeDataset$a1Cat
## t = 0.98186, df = 150.27, p-value = 0.3277
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1658423 0.4934700
## sample estimates:
## mean in group Less mean in group More
## 0.08190691 -0.08190691
t.test(PC4~algaeDataset$a1Cat,data=algaetyp_pca)
##
## Welch Two Sample t-test
##
## data: PC4 by algaeDataset$a1Cat
## t = 1.7282, df = 137.97, p-value = 0.0862
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.03215227 0.47819324
## sample estimates:
## mean in group Less mean in group More
## 0.1115102 -0.1115102
t.test(PC5~algaeDataset$a1Cat,data=algaetyp_pca)
##
## Welch Two Sample t-test
##
## data: PC5 by algaeDataset$a1Cat
## t = -0.74733, df = 147.55, p-value = 0.4561
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.3289875 0.1484396
## sample estimates:
## mean in group Less mean in group More
## -0.04513696 0.04513696
t.test(PC6~algaeDataset$a1Cat,data=algaetyp_pca)
##
## Welch Two Sample t-test
##
## data: PC6 by algaeDataset$a1Cat
## t = -0.045498, df = 167.61, p-value = 0.9638
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.2143380 0.2046813
## sample estimates:
## mean in group Less mean in group More
## -0.002414193 0.002414193
t.test(PC7~algaeDataset$a1Cat,data=algaetyp_pca)
##
## Welch Two Sample t-test
##
## data: PC7 by algaeDataset$a1Cat
## t = -1.9193, df = 174.44, p-value = 0.05658
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.260408434 0.003637506
## sample estimates:
## mean in group Less mean in group More
## -0.06419273 0.06419273
F-test for PCA:
var.test(PC1~algaeDataset$a1Cat,data=algaetyp_pca)
##
## F test to compare two variances
##
## data: PC1 by algaeDataset$a1Cat
## F = 2.0862, num df = 91, denom df = 91, p-value = 0.000541
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 1.379658 3.154552
## sample estimates:
## ratio of variances
## 2.086193
var.test(PC2~algaeDataset$a1Cat,data=algaetyp_pca)
##
## F test to compare two variances
##
## data: PC2 by algaeDataset$a1Cat
## F = 6.2232, num df = 91, denom df = 91, p-value = 2.22e-16
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 4.115546 9.410091
## sample estimates:
## ratio of variances
## 6.223156
var.test(PC3~algaeDataset$a1Cat,data=algaetyp_pca)
##
## F test to compare two variances
##
## data: PC3 by algaeDataset$a1Cat
## F = 2.7002, num df = 91, denom df = 91, p-value = 3.605e-06
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 1.785688 4.082929
## sample estimates:
## ratio of variances
## 2.700155
var.test(PC4~algaeDataset$a1Cat,data=algaetyp_pca)
##
## F test to compare two variances
##
## data: PC4 by algaeDataset$a1Cat
## F = 3.5964, num df = 91, denom df = 91, p-value = 3.678e-09
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 2.378376 5.438095
## sample estimates:
## ratio of variances
## 3.596364
var.test(PC5~algaeDataset$a1Cat,data=algaetyp_pca)
##
## F test to compare two variances
##
## data: PC5 by algaeDataset$a1Cat
## F = 2.8699, num df = 91, denom df = 91, p-value = 9.306e-07
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 1.897970 4.339659
## sample estimates:
## ratio of variances
## 2.869937
var.test(PC6~algaeDataset$a1Cat,data=algaetyp_pca)
##
## F test to compare two variances
##
## data: PC6 by algaeDataset$a1Cat
## F = 0.54678, num df = 91, denom df = 91, p-value = 0.004368
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.3616024 0.8267947
## sample estimates:
## ratio of variances
## 0.5467824
var.test(PC7~algaeDataset$a1Cat,data=algaetyp_pca)
##
## F test to compare two variances
##
## data: PC7 by algaeDataset$a1Cat
## F = 1.5259, num df = 91, denom df = 91, p-value = 0.04521
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 1.009126 2.307341
## sample estimates:
## ratio of variances
## 1.525909
Levene’s test for PCA with algae1:
(LTPC1_algae <- leveneTest(PC1~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 7.4199 0.007079 **
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 2.4241 0.1212
## 182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 8.5103 0.003976 **
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 10.753 0.001247 **
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 21.654 6.27e-06 ***
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 6.5081 0.01156 *
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 2.6048 0.1083
## 182
(LTPC8_algae <- leveneTest(PC8~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0631 0.802
## 182
Levene’s test for PCA with algae2:
(LTPC1_algae <- leveneTest(PC1~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.3361 0.5628
## 182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0341 0.8537
## 182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 2.8616 0.09243 .
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0631 0.802
## 182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.5538 0.4577
## 182
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0305 0.8616
## 182
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.5315 0.4669
## 182
(LTPC8_algae <- leveneTest(PC8~algaeDataset$a2Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 4e-04 0.9845
## 182
Levene’s test for PCA with algae3:
(LTPC1_algae <- leveneTest(PC1~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.2599 0.6108
## 182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.4843 0.4874
## 182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0728 0.7876
## 182
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 1.9103 0.1686
## 182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0484 0.8261
## 182
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.5406 0.4631
## 182
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 1.0675 0.3029
## 182
(LTPC8_algae <- leveneTest(PC8~algaeDataset$a3Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.1993 0.6558
## 182
Levene’s test for PCA with algae4:
(LTPC1_algae <- leveneTest(PC1~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 1.7754 0.1844
## 182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 2.4405 0.12
## 182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 2.0726 0.1517
## 182
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.7041 0.4025
## 182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 2.739 0.09965 .
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 2.9668 0.08669 .
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 2.7424 0.09944 .
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC8_algae <- leveneTest(PC8~algaeDataset$a4Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.2899 0.591
## 182
Levene’s test for PCA with algae5:
(LTPC1_algae <- leveneTest(PC1~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 2.5008 0.1155
## 182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.1026 0.7491
## 182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 3.0766 0.08111 .
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.4938 0.4832
## 182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 1.288 0.2579
## 182
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 5.5957 0.01906 *
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0044 0.9472
## 182
(LTPC8_algae <- leveneTest(PC8~algaeDataset$a5Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 4.5388 0.03448 *
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Levene’s test for PCA with algae6:
(LTPC1_algae <- leveneTest(PC1~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 1.9162 0.168
## 182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 2.4153 0.1219
## 182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.4671 0.4952
## 182
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.2279 0.6337
## 182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 1.4475 0.2305
## 182
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.4116 0.5219
## 182
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0039 0.9505
## 182
(LTPC8_algae <- leveneTest(PC8~algaeDataset$a6Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 6.5298 0.01143 *
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Levene’s test for PCA with algae7:
(LTPC1_algae <- leveneTest(PC1~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 1.6335 0.2029
## 182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.1209 0.7285
## 182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 4.9291 0.02764 *
## 182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0491 0.8248
## 182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0564 0.8126
## 182
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 1.0612 0.3043
## 182
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 1.88 0.172
## 182
(LTPC8_algae <- leveneTest(PC8~algaeDataset$a7Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 1.1521 0.2845
## 182
The above test significance is summarized as follows: a1 <- PC1,PC3,PC4,PC5 and PC6 a2 <- no significance a3 <- no significance a4 <- no significance a5 <- PC6 and PC8 a6 <- PC8 a7 <- PC3
From the below Scree diagram we conclude that upto PC5 it is significant to consider
plot(eigen_algaes, xlab = "Component number", ylab = "Component variance", type = "l", main = "Scree diagram")
plot(log(eigen_algaes), xlab = "Component number",ylab = "log(Component variance)", type="l",main = "Log(eigenvalue) diagram")
pairs(algae_pca$x[,1:7], ylim = c(-6,4),xlim = c(-6,4),panel=function(x,y,...){text(x,y,algaeDataset$a1Cat)})
PC1,PC2,PC3 and PC4 Thus a1 and a7 are significant with PC1,PC3 and PC4 only a1 -> PC1,PC3 and PC4 a7 -> PC3
PC1 is more correlated with PO4 and oPO4 (Phosphate) PC2 is more correlated with NO3 and NH4 (Nitrogen) PC3 is more correlated with Chla (Chlorophyll) PC4 is more correlated with Cl (Chloride)
chemicalCompositionAlgaes <- algaeDataset[,4:11]
scale.algae <- scale(chemicalCompositionAlgaes)
dist.algae <- dist(scale.algae,method = "euclidean")
cluster.algae <- hclust(dist.algae,method = "single")
par(mar=c(8, 4, 4, 2) + 0.1)
plot(as.dendrogram(cluster.algae),ylab="Distances between the chemical composition",main ="Cluster analysis dendogram")
algaesOnly <- algaeDataset[,12:18]
scale.alagesOnly <- scale(algaesOnly)
dist.algaeOnly <- dist(scale.alagesOnly,method="euclidean")
cluster.algaesOnly <- hclust(dist.algaeOnly,method = "single")
par(mar=c(8, 4, 4, 2) + 0.1)
plot(as.dendrogram(cluster.algaesOnly),ylab="Distances between different types of algaes",main ="Dendogram: Different types of Algaes")
Clustering is not useful for our dataset since we do not have any parameters to do clustering
library(psych)
## Warning: package 'psych' was built under R version 3.5.2
##
## Attaching package: 'psych'
## The following object is masked from 'package:car':
##
## logit
## The following object is masked from 'package:Hmisc':
##
## describe
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
vss(numericAlgaeData)
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs
## = np.obs, : The estimated weights for the factor scores are probably
## incorrect. Try a different factor extraction method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate =
## rotate, : A loading greater than abs(1) was detected. Examine the loadings
## carefully.
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs
## = np.obs, : The estimated weights for the factor scores are probably
## incorrect. Try a different factor extraction method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate =
## rotate, : An ultra-Heywood case was detected. Examine the results carefully
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate =
## rotate, : A loading greater than abs(1) was detected. Examine the loadings
## carefully.
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs
## = np.obs, : The estimated weights for the factor scores are probably
## incorrect. Try a different factor extraction method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate =
## rotate, : An ultra-Heywood case was detected. Examine the results carefully
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs
## = np.obs, : The estimated weights for the factor scores are probably
## incorrect. Try a different factor extraction method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate =
## rotate, : An ultra-Heywood case was detected. Examine the results carefully
##
## Very Simple Structure
## Call: vss(x = numericAlgaeData)
## VSS complexity 1 achieves a maximimum of 0.77 with 3 factors
## VSS complexity 2 achieves a maximimum of 0.89 with 5 factors
##
## The Velicer MAP achieves a minimum of NA with 1 factors
## BIC achieves a minimum of NA with 3 factors
## Sample Size adjusted BIC achieves a minimum of NA with 4 factors
##
## Statistics by number of factors
## vss1 vss2 map dof chisq prob sqresid fit RMSEA BIC SABIC complex
## 1 0.52 0.00 0.098 20 2.7e+02 2.6e-45 6.50 0.52 0.26 164 227 1.0
## 2 0.68 0.73 0.125 13 1.2e+02 5.4e-19 3.63 0.73 0.21 50 91 1.2
## 3 0.77 0.83 0.134 7 5.0e+01 1.3e-08 2.05 0.85 0.19 14 36 1.1
## 4 0.71 0.84 0.226 2 3.2e+01 9.1e-08 1.71 0.87 0.29 22 28 1.3
## 5 0.75 0.89 0.281 -2 7.5e+00 NA 0.73 0.95 NA NA NA 1.2
## 6 0.72 0.85 0.546 -5 1.4e-09 NA 0.86 0.94 NA NA NA 1.4
## 7 0.72 0.85 1.000 -7 8.8e-11 NA 0.87 0.94 NA NA NA 1.4
## 8 0.72 0.85 NA -8 8.8e-11 NA 0.87 0.94 NA NA NA 1.4
## eChisq SRMR eCRMS eBIC
## 1 2.9e+02 1.7e-01 0.199 187.6
## 2 8.1e+01 8.8e-02 0.130 12.7
## 3 1.1e+01 3.3e-02 0.065 -25.6
## 4 5.8e+00 2.4e-02 0.089 -4.6
## 5 5.4e-01 7.2e-03 NA NA
## 6 4.9e-11 6.9e-08 NA NA
## 7 4.5e-12 2.1e-08 NA NA
## 8 4.5e-12 2.1e-08 NA NA
#since vss complexity achieves a maximum of 0.89 with 5 factores we consider nfactors =5
fit.pc <- principal(numericAlgaeData, nfactors=5, rotate="varimax")
fit.pc
## Principal Components Analysis
## Call: principal(r = numericAlgaeData, nfactors = 5, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC2 RC3 RC5 RC4 h2 u2 com
## mxPH 0.05 -0.24 0.82 0.01 0.12 0.75 0.246 1.2
## mnO2 -0.27 0.04 -0.07 0.95 -0.11 0.99 0.012 1.2
## Cl 0.25 0.08 0.09 -0.11 0.95 0.99 0.014 1.2
## NO3 0.05 0.91 0.00 0.16 0.19 0.90 0.102 1.2
## NH4 0.13 0.91 -0.03 -0.11 -0.07 0.87 0.130 1.1
## oPO4 0.96 0.09 0.03 -0.13 0.13 0.97 0.034 1.1
## PO4 0.92 0.11 0.12 -0.21 0.19 0.96 0.044 1.3
## Chla 0.08 0.20 0.86 -0.09 -0.01 0.79 0.211 1.1
##
## RC1 RC2 RC3 RC5 RC4
## SS loadings 1.94 1.80 1.44 1.02 1.01
## Proportion Var 0.24 0.22 0.18 0.13 0.13
## Cumulative Var 0.24 0.47 0.65 0.77 0.90
## Proportion Explained 0.27 0.25 0.20 0.14 0.14
## Cumulative Proportion 0.27 0.52 0.72 0.86 1.00
##
## Mean item complexity = 1.2
## Test of the hypothesis that 5 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.06
## with the empirical chi square 32.76 with prob < NA
##
## Fit based upon off diagonal values = 0.97
round(fit.pc$values, 3)
## [1] 2.734 1.750 1.280 0.774 0.670 0.515 0.209 0.068
fit.pc$loadings
##
## Loadings:
## RC1 RC2 RC3 RC5 RC4
## mxPH -0.243 0.824 0.118
## mnO2 -0.266 0.949 -0.109
## Cl 0.247 -0.109 0.948
## NO3 0.914 0.159 0.185
## NH4 0.127 0.914 -0.113
## oPO4 0.962 -0.127 0.125
## PO4 0.923 0.109 0.123 -0.208 0.186
## Chla 0.199 0.857
##
## RC1 RC2 RC3 RC5 RC4
## SS loadings 1.936 1.797 1.443 1.017 1.014
## Proportion Var 0.242 0.225 0.180 0.127 0.127
## Cumulative Var 0.242 0.467 0.647 0.774 0.901
# Loadings with more digits
for (i in c(1,3,2,4)) { print(fit.pc$loadings[[1,i]])}
## [1] 0.04643745
## [1] 0.8236389
## [1] -0.2433823
## [1] 0.01081039
# Communalities
fit.pc$communality
## mxPH mnO2 Cl NO3 NH4 oPO4 PO4
## 0.7538696 0.9882599 0.9860238 0.8984617 0.8702357 0.9656365 0.9563808
## Chla
## 0.7890466
# Rotated factor scores, Notice the columns ordering: RC1, RC3, RC2 and RC4
fit.pc$scores
## RC1 RC2 RC3 RC5 RC4
## 1 0.147015533 0.624417808 1.006248279 0.42333281 0.139847361
## 2 4.039051814 -0.860687452 -0.318872427 0.68589149 -0.530716445
## 3 0.654408226 0.140386860 0.098951591 1.26819598 -0.108354763
## 4 -0.523917283 -0.303785790 -0.490345035 -1.85097335 0.807102702
## 5 -0.492003039 0.843392307 -0.090618021 0.20844443 0.640499444
## 6 -0.683133227 0.812700545 0.758004259 1.82445537 0.817259832
## 7 -0.187717717 -0.459403506 -0.258056217 0.51852653 0.735668881
## 8 -0.444819516 0.098995002 -0.215737179 0.67037545 0.571722604
## 9 -0.913346028 -0.539037690 0.461739275 -2.51503934 -0.360189944
## 10 -0.487856050 -0.377505368 -0.506739547 0.15237625 -0.613457149
## 11 -0.664125936 -0.278746231 -0.773462953 0.18354071 -0.591466687
## 12 -0.561068761 -0.221243973 -1.062664638 0.78138464 -0.584790076
## 13 -0.818343988 -0.023575541 0.506715214 -0.18611348 -0.960750065
## 14 -0.534607491 -0.314620508 -0.735853205 0.89049095 -0.616030178
## 15 -0.527999941 -0.343127020 -0.547172914 -0.00813172 -0.713477314
## 16 -0.275881727 -0.296044159 -0.919585072 0.75038645 -0.720193865
## 17 -0.360413111 -0.341380098 -0.643630895 1.01895452 -0.629166655
## 18 -0.481690221 -0.277864704 -0.904852136 0.02942938 -0.664871702
## 19 -0.269587986 -0.188116594 -1.213759574 0.29219975 -0.721053874
## 20 5.277143707 1.616814184 -1.031560198 -1.77445659 -1.576979831
## 21 4.419390350 0.123030724 -0.501297290 1.84532693 -0.066818400
## 22 -0.673878668 -0.233291276 -1.405156505 -0.40293605 -0.856755861
## 23 -0.681269443 -0.075869376 -0.526297122 0.30488077 -0.045089217
## 24 -0.853226609 -0.155394958 -0.864502874 -0.60560420 -0.530893497
## 25 -0.848062024 -0.298584483 -0.589946596 -0.16446838 -0.498219417
## 26 -0.622210977 0.035809727 -0.602829653 0.51263779 -0.406683795
## 27 -0.876715953 -0.083283180 -1.550498500 -0.76377972 -0.594539121
## 29 -0.527980304 -0.480887594 -0.435108993 0.09742609 -0.455043531
## 30 -0.550373423 -0.302638931 -1.384877168 0.49344555 -0.676036784
## 31 0.375325266 -0.031778920 -1.013975161 1.40443856 -0.636457452
## 32 1.985327230 -0.334537140 -0.379131174 1.13829343 -0.649417457
## 33 0.069877127 -0.148981968 -0.513153644 0.90783278 -0.422848654
## 34 -0.740705791 0.610431135 0.104169188 -0.01145274 -0.231682027
## 35 -1.068958621 1.077301215 -0.119191244 -1.36692276 -0.707040758
## 36 -0.418831972 0.188225962 0.418815029 -0.33206497 -0.229118110
## 37 -0.745313018 -0.539406016 -0.038221426 0.55623519 -0.667684144
## 39 1.318434508 -0.251582545 0.174525051 0.36699072 -0.739712231
## 40 1.355507554 -0.159189282 -0.139855743 1.03038381 -0.635479412
## 41 0.675111256 0.118060684 -0.525805270 -1.12107748 0.692545291
## 42 -0.200336287 0.083548615 0.042978623 -0.83184076 0.226125993
## 43 1.855489991 0.371744026 0.418763768 0.25655712 -0.120315625
## 44 1.974729491 0.176431103 0.089534093 0.75432619 0.021536107
## 45 -0.645879346 -0.118498130 0.165413802 1.87952267 0.968171288
## 46 -0.645522916 -0.072055537 -0.018323926 1.52446835 1.320741662
## 47 -0.677545086 -0.023871193 -0.436806443 1.23794722 0.850675388
## 49 -0.246908481 -0.076408706 -0.851184004 0.05934571 -0.497171223
## 50 -0.655527379 0.101724489 -0.915634043 0.56695927 -0.434799021
## 51 -0.696558332 0.211781005 -0.689908157 0.27156550 -0.027784153
## 52 -0.958580726 -0.296228267 -0.345296774 -0.76398569 -0.163629328
## 53 -0.667953921 -0.383069894 -0.523591672 0.54770144 -0.601901025
## 54 -0.808582042 -0.389298074 -0.543992978 -0.33735986 -0.652330750
## 64 -0.726698172 -0.275889492 -0.908235015 0.36776836 -0.665811870
## 65 -0.640545460 -0.119396493 -1.379104374 0.67776846 -0.704341333
## 66 -0.768855238 -0.294561967 -1.089210364 0.01525877 -0.734010543
## 67 -0.769185004 -0.178789655 -1.400835455 -0.17881928 -0.772802871
## 68 -0.614713352 -0.141661190 -1.599250867 0.80694928 -0.744390303
## 69 1.340431032 -0.048233859 -1.017977497 -3.10976167 -0.918837124
## 70 1.146104810 0.104733442 -1.278087462 -3.06834112 -0.922955613
## 71 0.951159243 0.215548743 -0.425643987 -0.84914961 -0.738342589
## 72 -0.249108950 -0.161544968 0.265816549 -0.31314549 0.053991145
## 73 -0.483213413 0.693472063 -0.184360645 0.61642226 0.141642591
## 74 0.435296898 -0.097936972 0.082129325 -0.12875595 1.836236299
## 75 0.064324784 -0.185399757 -0.027341612 -0.77230249 1.799516101
## 76 0.320168640 -0.166563287 1.406302421 0.56302846 -0.055756409
## 77 -0.363564227 -0.385590378 -0.238482385 0.16311750 -0.198145322
## 78 -0.555462756 -0.423739948 -0.442382574 -1.55192461 -0.313947922
## 79 -0.722303944 -0.399079743 -0.479883816 -2.68872956 -0.358527749
## 80 -0.320743889 0.004483526 -1.018465796 -0.14160511 -0.572742622
## 81 -0.405612342 0.067865022 -1.118785308 0.06796570 -0.587630788
## 82 -0.461536030 0.298404726 -1.115531504 0.88635641 -0.489492833
## 83 -0.446915073 0.462327432 -0.530835138 -0.26542695 -0.587099238
## 84 -0.347165821 0.403238460 -1.047052300 0.78609166 -0.420441563
## 85 0.718369915 0.204227738 -1.016321707 0.81726699 -0.354418194
## 86 0.621740535 0.154998989 -0.966057635 -1.20759749 -0.015822249
## 87 0.169187831 0.113153860 -1.106469188 0.63087530 -0.133123606
## 88 3.676469959 1.134190418 -0.907686053 -1.75156578 -1.222461903
## 89 3.305740377 1.193746771 -0.897548049 0.85896974 -0.636994991
## 90 1.086291344 -0.156620403 1.140078377 0.31799468 1.388339270
## 91 1.926032760 -0.658009144 0.166961510 1.02995165 2.555307384
## 92 1.232439387 -0.149873446 -0.278449612 1.20436912 0.978848203
## 93 0.482182982 -0.012098007 1.372129133 0.16200340 0.123815212
## 94 0.940234675 -0.309668070 -0.547629737 0.83473860 0.395190976
## 95 1.009544069 -0.031138925 -0.472455304 1.53316339 0.383665618
## 96 -0.303349966 -0.527193207 0.753834992 0.51579598 0.267795007
## 97 0.104108589 -0.377677875 2.946461143 -1.43934983 -0.175680733
## 98 -0.073514447 -0.106020231 3.508493383 -1.96791906 -0.462437010
## 99 -0.296922800 -0.065260222 -0.671959734 -1.13597932 1.371508703
## 100 -0.302799895 0.469256064 -0.109154030 -0.36329331 0.975164121
## 101 -0.392225676 0.111121209 0.013838896 -1.00917887 0.323657175
## 102 -0.675732493 -0.125195287 -0.651285930 -1.26993322 0.937706251
## 103 -0.366113844 0.055290776 -0.423005181 -1.74851433 0.374351937
## 104 0.675812437 0.756788757 -1.047033360 0.15593527 0.369835506
## 105 0.207661031 0.756548962 1.342905827 0.29110200 -0.309112665
## 106 -0.236907664 -0.479693164 0.425490315 -0.61365096 0.254608494
## 107 0.320295792 1.056749089 1.204700235 0.97316139 -0.149715526
## 108 -0.225022849 0.220694581 0.313589677 0.86962893 0.068448375
## 109 -0.390577400 -0.006722627 0.742257788 -1.35744855 -0.181675123
## 110 0.048793047 0.262351804 0.196099482 0.98821341 -0.143356154
## 111 -0.766301692 -0.526858217 0.452719172 0.21997073 -0.525130433
## 112 -0.622332718 -0.378528118 -0.155729992 0.78124672 -0.519480520
## 113 -0.627346594 -0.420860784 0.270712606 1.03951775 -0.502173284
## 114 -0.613983925 -0.450242151 -0.775422822 -1.54874625 0.238530885
## 115 -0.427220126 -0.491993889 -0.427213629 0.09362437 0.377924098
## 117 -0.533744072 -0.669417806 0.363725484 0.96978896 -0.678026133
## 118 -0.657197303 -0.537160948 0.057141390 0.86808663 -0.593022243
## 119 2.009484672 -0.242729968 0.529539198 -0.88645978 0.149563816
## 120 1.344566580 -0.289705554 -0.307585139 -0.42014508 1.652968076
## 121 0.999028157 0.289993420 0.009286379 0.61880153 0.027005583
## 122 0.911642873 0.035419051 0.055712076 -0.45097653 -0.195691546
## 123 0.964753909 0.157939453 -0.256865501 0.46228959 0.086459332
## 124 -0.064627017 -0.098136538 -1.001545766 0.46704496 -0.667008405
## 125 0.020339396 -0.408004695 0.057326976 0.29115548 -0.643548730
## 126 -0.066558972 -0.476843274 0.341759241 0.79154293 -0.510036118
## 127 0.409402381 0.371217427 3.615300504 1.31645151 -0.671383209
## 128 0.336654629 0.256795011 4.070252002 -0.78380195 -1.087054900
## 129 0.140773805 0.126037348 1.423743584 0.45507348 -0.523340823
## 130 -0.374724358 -0.418430180 0.501558451 0.35802793 -0.611428176
## 131 -0.388132791 -0.468600767 -0.066017648 -0.66982252 -0.626078536
## 132 -0.203601418 -0.200258035 -1.207641604 0.32337834 -0.687445198
## 133 -0.802993263 1.175959035 -0.283758426 0.10994829 3.227861738
## 134 0.143623958 -0.021631251 -0.953508118 0.25705523 7.553456141
## 135 -0.365926292 0.215177241 -0.430537903 1.39372049 2.186624758
## 136 1.061515822 -0.080913191 -0.514435690 0.47484207 -0.176552000
## 137 -0.197215708 0.024512247 -0.248328421 1.20247427 0.105307524
## 138 -0.303082760 -0.516337675 0.398025233 0.28218733 -0.071309429
## 139 -0.439370349 -0.496304147 -0.376845988 -1.34389893 -0.072282344
## 140 -0.020742292 0.794319410 -0.411431235 1.15368603 0.456762626
## 141 0.331730735 0.040777987 -0.278080148 -0.95183439 0.155305260
## 142 -0.639353312 -0.281884779 -0.657215716 -0.07643013 -0.591587355
## 143 -0.679116587 -0.196510301 -0.484806540 0.37424323 -0.502756714
## 144 -0.418039360 0.913881744 0.004938558 -1.79752930 0.851531579
## 145 -0.396473817 0.795424528 -0.968993928 -0.99022790 1.107852015
## 146 -0.009753899 0.983344321 -0.528267009 -1.07936012 0.432438319
## 147 -0.374424751 -0.228595932 0.681287770 -0.54162311 -0.172494519
## 148 -0.510473908 -0.254272985 0.611651328 0.21531280 -0.070073777
## 149 -0.304934467 -0.409239179 0.284827296 -0.00190364 0.178574078
## 150 0.059219240 -0.434415907 0.853221303 -1.74027309 -0.236025563
## 151 -0.433207838 -0.388207082 1.288100074 0.87954436 0.068331865
## 152 -0.854450184 -0.045591727 -0.443887556 -2.25767454 0.198239602
## 153 -1.795223147 12.259771905 0.615477391 0.26400075 -0.603133702
## 154 -1.088205770 -0.181811453 -0.697397543 -1.46176792 2.013645736
## 155 -0.861352663 0.442948370 0.077460715 0.47931551 1.355205080
## 156 0.876942831 0.436529535 -0.081236618 -2.24065282 0.610701336
## 157 1.006183169 0.374056832 -0.502197193 -1.57938087 -0.005769989
## 158 -0.680016908 -0.463763981 0.949140213 -2.43110849 0.004451977
## 159 -0.555561664 -0.311757984 0.679013222 0.51389901 -0.444238712
## 160 -0.388431424 -0.190069059 0.991825352 0.90277859 -0.421013321
## 162 0.492480865 -0.377183050 4.081457408 -1.17256499 -0.760184599
## 163 1.039895281 -0.265632383 3.222210998 0.11293168 -0.886747140
## 164 -0.726310133 -0.129221704 3.099156693 1.42019332 -0.300187606
## 165 -0.481119202 0.265823072 -1.221749724 0.13237784 -0.386759808
## 166 0.247707658 0.291027106 -1.069628702 0.68557720 -0.374745404
## 167 -0.056927352 -0.426746407 2.350882286 -1.85910286 0.458390180
## 168 0.141986394 -0.403745027 0.771087856 0.98092826 0.367865615
## 169 1.333257432 -0.138202667 0.522290376 0.37938460 -0.261549171
## 170 1.145834716 -0.092396627 -0.341015556 0.04120185 -0.339735794
## 171 1.164564746 0.045152855 0.202693445 -0.83854606 0.668489364
## 172 2.263084339 -0.104601175 -0.812380775 -0.45378058 1.756721308
## 173 -0.045142830 -0.183618944 -0.163591437 0.27819986 1.440766224
## 174 -0.332809650 -0.367490495 0.322345866 -0.66454657 0.690630170
## 175 -0.222051674 -0.121679133 0.882770038 0.96712062 3.612508805
## 176 0.137689362 -0.477947714 1.147316352 -0.62931658 3.045022424
## 177 -0.621110343 -0.623529717 0.463039863 0.60981555 -0.585447628
## 178 -0.657558785 -0.456592220 -0.281431230 0.46512823 -0.655120220
## 179 -0.729366376 -0.520514580 0.086324548 0.34018146 -0.583676262
## 180 -0.797039368 -0.615651812 0.348015449 0.27524769 -0.634993636
## 181 -0.825823391 -0.505090818 -0.164828961 -0.07495866 -0.678448981
## 182 -0.764287261 -0.562493480 0.313961336 0.42738938 -0.646724903
## 183 -0.749722090 -0.496740914 0.025601322 0.17976297 -0.646190193
## 185 -0.438928429 -0.502093469 -0.260579893 0.29397986 -0.643950290
## 186 0.527539128 0.280463475 1.780359202 1.10055709 -0.227063440
## 187 -0.256846149 -0.179528981 0.959645205 1.22106134 -0.274615499
## 188 -0.420602994 -0.225724535 0.447187193 -0.38045915 -0.348954157
## 189 -0.196793401 -0.217143933 0.786339597 0.87850616 -0.349389956
## 190 -0.278585889 -0.309265015 0.870102633 -0.65116421 -0.707805649
## 191 -0.263552794 -0.437565163 0.595089438 1.04258039 -0.390366230
## 192 -0.531082354 -0.421577214 0.302815161 0.49000305 -0.507874819
## 193 -0.377991705 -0.458502784 -0.063708281 -0.52043941 -0.696715669
## 194 -0.223236572 -0.134357939 0.962272273 0.94083690 -0.326428747
## 195 -0.712460875 -0.289391715 0.332559062 -0.57656471 -0.459376997
## 196 -0.388474269 -0.170003313 0.078265528 -0.22990830 -0.346552311
## 197 -0.337658912 -0.206311635 0.071509359 0.63268365 -0.424020578
## 198 -0.528253653 -0.111782754 0.549867186 -0.84023775 2.002219838
## 200 -0.435022425 -0.275601895 0.576024268 -0.92901750 0.887855482
# Play with FA utilities
fa.parallel(numericAlgaeData) # See factor recommendation
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs
## = np.obs, : The estimated weights for the factor scores are probably
## incorrect. Try a different factor extraction method.
## Parallel analysis suggests that the number of factors = 3 and the number of components = 3
fa.plot(fit.pc) # See Correlations within Factors
fa.diagram(fit.pc) # Visualize the relationship
#Now we will visualize according to oblimin rotate function
library(GPArotation)
fit.pc_2 <- principal(numericAlgaeData, nfactors=5, rotate="oblimin")
fit.pc_2
## Principal Components Analysis
## Call: principal(r = numericAlgaeData, nfactors = 5, rotate = "oblimin")
##
## Warning: A Heywood case was detected.
## Standardized loadings (pattern matrix) based upon correlation matrix
## TC1 TC2 TC3 TC5 TC4 h2 u2 com
## mxPH 0.01 -0.25 0.82 0.05 0.09 0.75 0.246 1.2
## mnO2 -0.01 0.02 -0.01 0.98 -0.05 0.99 0.012 1.0
## Cl 0.03 0.03 0.00 -0.05 0.97 0.99 0.014 1.0
## NO3 -0.02 0.91 0.01 0.16 0.17 0.90 0.102 1.1
## NH4 0.05 0.92 -0.01 -0.13 -0.12 0.87 0.130 1.1
## oPO4 1.01 -0.01 -0.04 0.04 -0.02 0.97 0.034 1.0
## PO4 0.93 0.02 0.05 -0.05 0.04 0.96 0.044 1.0
## Chla 0.01 0.21 0.87 -0.06 -0.07 0.79 0.211 1.1
##
## TC1 TC2 TC3 TC5 TC4
## SS loadings 1.93 1.79 1.43 1.03 1.03
## Proportion Var 0.24 0.22 0.18 0.13 0.13
## Cumulative Var 0.24 0.46 0.64 0.77 0.90
## Proportion Explained 0.27 0.25 0.20 0.14 0.14
## Cumulative Proportion 0.27 0.52 0.71 0.86 1.00
##
## With component correlations of
## TC1 TC2 TC3 TC5 TC4
## TC1 1.00 0.18 0.14 -0.41 0.37
## TC2 0.18 1.00 -0.02 0.01 0.10
## TC3 0.14 -0.02 1.00 -0.11 0.15
## TC5 -0.41 0.01 -0.11 1.00 -0.16
## TC4 0.37 0.10 0.15 -0.16 1.00
##
## Mean item complexity = 1.1
## Test of the hypothesis that 5 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.06
## with the empirical chi square 32.76 with prob < NA
##
## Fit based upon off diagonal values = 0.97
fa.plot(fit.pc_2)
fa.diagram(fit.pc_2)